I have collection of such classes:
public class class1
{
public double first {get;set;}
public double second {get;set;}
public void divide(object sender, RoutedEventArgs e)
{
first/=2;
second/=2;
}
}
ObservableCollection<class1> collection1;
That are displayed using wpf and databinding:
<Listbox ItemsSource="{Binding collection1}" >
<ListBox.ItemTemplate>
<DataTemplate>
<WrapPanel>
<TextBox Text="{Binding first}" />
<TextBox Text="{Binding second}" />
<Button Content="Divide" />
</WrapPanel>
</DataTemplate>
</ListBox.ItemTemplate>
My question is: can I somehow bind each button to it's instance's function divide?
Pravesh Singh
23-Sep-2013Assuming you're using a code-behind (.xaml.cs), you can define an event handler like this there:
In class1:
In XAML: